package com.castle.fortress.admin.oa.service.impl;

import cn.hutool.core.util.StrUtil;

import com.castle.fortress.common.utils.ConvertUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.castle.fortress.admin.oa.entity.DateHolidayEntity;
import com.castle.fortress.admin.oa.dto.DateHolidayDto;
import com.castle.fortress.admin.oa.mapper.DateHolidayMapper;
import com.castle.fortress.admin.oa.service.DateHolidayService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;

/**
 * 日期节假日表 服务实现类
 *
 * @author whc
 * @since 2022-11-04
 */
@Service
public class DateHolidayServiceImpl extends ServiceImpl<DateHolidayMapper, DateHolidayEntity> implements DateHolidayService {
    /**
    * 获取查询条件
    * @param dateHolidayDto
    * @return
    */
    public QueryWrapper<DateHolidayEntity> getWrapper(DateHolidayDto dateHolidayDto){
        QueryWrapper<DateHolidayEntity> wrapper= new QueryWrapper();
        if(dateHolidayDto != null){
            DateHolidayEntity dateHolidayEntity = ConvertUtil.transformObj(dateHolidayDto,DateHolidayEntity.class);
        }
        return wrapper;
    }


    @Override
    public IPage<DateHolidayDto> pageDateHoliday(Page<DateHolidayDto> page, DateHolidayDto dateHolidayDto) {
        QueryWrapper<DateHolidayEntity> wrapper = getWrapper(dateHolidayDto);
        Page<DateHolidayEntity> pageEntity = new Page(page.getCurrent(), page.getSize());
        Page<DateHolidayEntity> dateHolidayPage=baseMapper.selectPage(pageEntity,wrapper);
        Page<DateHolidayDto> pageDto = new Page(dateHolidayPage.getCurrent(), dateHolidayPage.getSize(),dateHolidayPage.getTotal());
        pageDto.setRecords(ConvertUtil.transformObjList(dateHolidayPage.getRecords(),DateHolidayDto.class));
        return pageDto;
    }


    @Override
    public List<DateHolidayDto> listDateHoliday(DateHolidayDto dateHolidayDto){
        QueryWrapper<DateHolidayEntity> wrapper = getWrapper(dateHolidayDto);
        List<DateHolidayEntity> list = baseMapper.selectList(wrapper);
        return ConvertUtil.transformObjList(list,DateHolidayDto.class);
    }
}

